package com.ssm.task;


import java.util.concurrent.Executor;
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
@Configuration
//@ComponentScan("com.ssm.task")
@EnableAsync  // 启用异步任务  这个是spring多线程
public class ThreadConfig  {
 
     // 这里是声明一个bean，类似于xml中的<bean>标签。
     // Executor 就是一个线程池
     @Bean
     public Executor getExecutor() {
          ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
          executor.setCorePoolSize(5);
          executor.setMaxPoolSize(10);
          executor.setQueueCapacity(25);
          executor.initialize();
          return executor;
     }
}
